import axios, { type ResDataType } from "./index";
type SearchOption = {
  keyword: string;
  isStar: boolean;
  isDeleted: boolean;
  pageSize: number;
  page: number;
};
/**
 * @description 获取单个问卷信息
 * @param id
 * @returns
 */
export async function getQuestionService(id: string): Promise<ResDataType> {
  const url = `/api/question/${id}`;
  const data = await axios.get(url);
  return data;
}
/**
 * 创建问卷
 * @returns
 */
export async function createQuestionService() {
  const url = "/api/question";
  const data = (await axios.post(url)) as ResDataType;
  return data;
}
/**
 * @description 获取问卷数据
 * @returns
 */
export async function getQuestionListService(
  params: Partial<SearchOption> = {}
): Promise<ResDataType> {
  const url = "/api/question";
  const data = (await axios.get(url, {
    params,
  })) as ResDataType;
  return data;
}
/**
 * @description 更新单个问卷数据
 */

export async function updateQuestionService(
  id: string,
  opt: {
    [key: string]: any;
  }
): Promise<ResDataType> {
  const url = `/api/question/${id}`;
  const data = (await axios.patch(url, opt)) as ResDataType;
  return data;
}
/**
 * @description 复制问卷数据
 */

export async function duplicateQuestionService(
  id: string
): Promise<ResDataType> {
  const url = `/api/question/duplicate/${id}`;
  const data = (await axios.post(url)) as ResDataType;
  return data;
}
/**
 * @description 彻底删除问卷
 */
export async function deleteQuestionService(
  ids: string[]
): Promise<ResDataType> {
  const url = "/api/question";
  const data = await axios.delete(url, { data: { ids } });
  return data;
}
